package aso.fighting_groups;

import sim.engine.SimState;
import sim.engine.Steppable;

/**
 * The class that handles food spawning.
 */
class FoodManager implements Steppable {

    /**
     * UID for serialization.
     */
    private static final long serialVersionUID = -4436149131961716012L;

    @Override
    public final void step(final SimState state) {
        FightingGroups fg = (FightingGroups) state;
        
        //a random amount of food is placed at a location based on the food spawn probability
        for (int x = 0; x < fg.getGridWidth(); ++x) {
            for (int y = 0; y < fg.getGridHeight(); ++y) {
                if (fg.getFoodGrid().field[x][y] == 0 && fg.random.nextDouble() < fg.getFoodSpawnProbability()) {
                    fg.getFoodGrid().field[x][y] = fg.random.nextDouble() * fg.getMaxFood();
                }
                if (fg.getFoodGrid().field[x][y] > 0) {
                    fg.getSmellGrid().field[x][y] = fg.getMaxSmell() * (fg.getFoodGrid().field[x][y] / fg.getMaxFood());
                }
            }
        }
    }

}
